package com.soilflow.web.controller.soilflow;

import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.core.page.TableDataInfo;
import com.soilflow.common.domain.LandNotice;
import com.soilflow.common.domain.dto.LandAuctionEnrollDto;
import com.soilflow.common.domain.dto.LandNoticeDto;
import com.soilflow.common.domain.vo.LandAuctionEnrollVo;
import com.soilflow.common.domain.vo.LandNoticeVo;
import com.soilflow.info.service.LandNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 土地公告
 */
@RestController
@RequestMapping("/notice/info")
public class NoticeInfoController extends BaseController {


    @Autowired
    private LandNoticeService landNoticeService;


    /**
     * 公告信息列表
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo landNoticeList(LandNoticeDto dto)
    {
        startPage();
        List<LandNoticeVo> list = landNoticeService.landNoticeList(dto);
        return getDataTable(list);
    }


    /**
     * 添加通知
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addLandNotice(@RequestBody  LandNoticeDto dto){
        dto.setUserId(getUserId());
        dto.setDeptId(getDeptId());
        Boolean result = landNoticeService.addLandNotice(dto);
        if (result){
            return AjaxResult.success();
        }
        return AjaxResult.error("请勿重复添加");
    }

    /**
     * 删除公告
     * @param ids
     * @return
     */
    @DeleteMapping("/del/{ids}")
    public AjaxResult delLandNotice(@PathVariable List<Long> ids){
        landNoticeService.delLandNotice(ids);
        return AjaxResult.success();
    }

    /**
     * 更新公告
     * @param dto
     * @return
     */
    @PutMapping("/update")
    public AjaxResult updateLandNotice(@RequestBody LandNoticeDto dto){
        dto.setDeptId(getDeptId());
        dto.setUserId(getUserId());
        landNoticeService.updateLandNotice(dto);
        return AjaxResult.success();
    }

    /**
     * 回显详情
     * @return
     */
    @GetMapping("/detail/{id}")
    public AjaxResult getLandNoticeById(@PathVariable Long id){
        LandNotice vo = landNoticeService.getLandNoticeById(id);
        return AjaxResult.success(vo);
    }
    /**
     * 今年土地竞拍数量
     */
    @GetMapping("/number")
    public AjaxResult number(){
        return AjaxResult.success(landNoticeService.number());
    }
    /**
     * 查询今年竞拍类型为公告的数量
     */
    @GetMapping("/announcements")
    public AjaxResult announcements(){
        return AjaxResult.success(landNoticeService.announcements());
    }
    /**
     * 查询今年竞拍类型为通知的数量
     */
    @GetMapping("/notice")
    public AjaxResult notice(){
        return AjaxResult.success(landNoticeService.notice());
    }

}
